﻿using System;
using System.Collections;
using System.Text;
using System.Drawing;

using lib.type;

namespace lib
{
    class LibObject
    {
        public enum ORIENTATION_MODES
        {
            NONE,
            HORIZONTAL,
            VERTICAL,
            ALL
        };

        private string name;
        private ORIENTATION_MODES orientation;
        private Hashtable properties;
        private Bitmap imageHorizontal;
        private Bitmap imageVertical;

        public LibObject()
        {
            this.properties = new Hashtable();
        }

        public string getName()
        {
            return this.name;
        }

        public void setName(string name)
        {
            this.name = name;
        }

        public ORIENTATION_MODES getOrientation()
        {
            return this.orientation;
        }

        public void setOrientation(ORIENTATION_MODES orientation)
        {
            this.orientation = orientation;
        }

        public Hashtable getProperties()
        {
            return this.properties;
        }

        public Bitmap getImageHorizontal()
        {
            return this.imageHorizontal;
        }

        public void setImageHorizontal(Bitmap image)
        {
            this.imageHorizontal = image;
        }

        public Bitmap getImageVertical()
        {
            return this.imageVertical;
        }

        public void setImageVertical(Bitmap image)
        {
            this.imageVertical = image;
        }

        public Property getPropertyByName(string name)
        {
            Property property = null;
            foreach (DictionaryEntry de in this.properties)
            {
                if (de.Key.Equals(name))
                {
                    try { property = (Property)de.Value; }
                    catch (Exception ex) { Console.WriteLine("LibObject - getPropertyByName - " + ex.Message); }
                }
            }
            return property;
        }

        public bool insertProperty(string name, Property property)
        {
            try
            {
                bool propertyFound = true;
                foreach (DictionaryEntry de in this.properties)
                {
                    if (de.Key.Equals(name))
                    {
                        propertyFound = false;
                        break;
                    }
                }

                if (propertyFound)
                    this.properties.Add(name, property);

                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("LibObject - insertProperty - " + ex.Message);
                return false;
            }
        }

        public bool updateProperty(string name, Property property)
        {
            try
            {
                foreach (DictionaryEntry de in this.properties)
                {
                    if (de.Key.Equals(name))
                    {
                        this.properties.Remove(name);
                        break;
                    }
                }
                this.properties.Add(name, property);

                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("LibObject - updateProperty - " + ex.Message);
                return false;
            }
        }

        public bool deleteProperty(string name)
        {
            try
            {
                foreach (DictionaryEntry de in this.properties)
                {
                    if (de.Key.Equals(name))
                    {
                        this.properties.Remove(name);
                        break;
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("LibObject - deleteProperty - " + ex.Message);
                return false;
            }
        }

        public string toString()
        {
            return this.name;
        }
    }
}
